﻿
using System;
using System.Collections.Generic;
using System.Text;

using System.Linq;
using OddUserManager.Data.IRepositories;
using OddUserManager.Model;

namespace OddUserManager.Service.IServices
{
    public class RoleService : IRoleService
    {
        private readonly IRoleRepository _repository;
        public RoleService(IRoleRepository repository)
        {
            _repository = repository;
        }

        public void DeleteBatchRole(List<int> ids)
        {
            _repository.DeleteBatch(ids);
        }

        public void DeleteRoleById(int id)
        {
            _repository.Delete(id);
        }

        public List<Role> GetAllList()
        {
            return _repository.GetAllList().OrderBy(it => it.Code).ToList();
        }

        public List<int> GetAllMenuListByRole(int roleId)
        {
            return _repository.GetAllMenuListByRole(roleId);
        }

        public List<Role> GetAllPageList(int startPage, int pageSize, out int rowCount)
        {
            return _repository.LoadPageList(startPage, pageSize, out rowCount, null, it => it.Code).ToList();
        }

        public Role GetRoleById(int id)
        {
            return _repository.Get(id);
        }

        public bool InsertOrUpdateRole(Role dto)
        {
            var isSuccess = _repository.InsertOrUpdate(dto);
            return isSuccess;
        }

        public bool UpdateRoleMenu(int roleId, List<RoleMenus> roleMenus)
        {
            return _repository.UpdateRoleMenu(roleId, roleMenus);
        }
    }
}
